/************************************************************************************************* PROGRAMMINFO ************************************************************************************************** Funktion: Die Helligkeit einer LEDs wird durch die Potentiometer mit Pulsweitenmodulation gesteuert. 1,30" Display an I2C LED an GPIO 27 Poti an A2 LED an GPIO 16 Poti an A4 LED an GPIO 17 Poti an A34 LED an GPIO 25 Poti an A39 ************************************************************************************************** Version: 19.04.2022 ************************************************************************************************** Board: ESP32vn IoT UNO ************************************************************************************************** C++ Arduino IDE V1.8.13 ************************************************************************************************** Einstellungen: https://dl.espressif.com/dl/package_esp32_index.json http://dan.drown.org/stm32duino/package_STM32duino_index.json https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json ************************************************************************************************* **************************************************************************************************/ #include #include #include #ifdef U8X8_HAVE_HW_SPI #include #endif #ifdef U8X8_HAVE_HW_I2C #include #endif //******** Kanal 1 ************************************ const int ADC_pin01 = 2; //P0ti an GPIO 2 int LED01 = 27; //LED GPIO27 int sensor_reading01 = 0; int dutyCycle01 =0; float analog_voltage01; unsigned long delayTime01; const int ledChannel01 = 1; // Auswahl LED-Channel 1; ESP32: 0-15 const int resolution01 = 8; // 8 bit Aufloesung 0-255. Aufloesung beim ESP32 ist 1-16Bit const int frequency01 = 1000; // Frequenz in Hz //**************************************************** //******** Kanal 2 ************************************ const int ADC_pin02 = 4; //Poti an GPIO 04 int LED02 = 16; //LED an GPIO 16 int sensor_reading02 = 0; int dutyCycle02 =0; float analog_voltage02; unsigned long delayTime02; const int ledChannel02 = 2; // Auswahl LED-Channel 2; ESP32: 0-15 const int resolution02 = 9; // 9 bit Aufloesung 0-255. Aufloesung beim ESP32 ist 1-16Bit const int frequency02 = 5000; // Frequenz in Hz //**************************************************** //******** Kanal 3 ************************************ const int ADC_pin03 = 34; //Poti an GPIO 34 int LED03 = 17; //LED an GPIO 17 int sensor_reading03 = 0; int dutyCycle03 =0; float analog_voltage03; unsigned long delayTime03; const int ledChannel03 = 10; // Auswahl LED-Channel 0; ESP32: 0-15 const int resolution03 = 10; // 10 bit Aufloesung 0-255. Aufloesung beim ESP32 ist 1-16Bit const int frequency03 = 10000; // Frequenz in Hz //**************************************************** //******** Kanal 4 ************************************ const int ADC_pin04 = 39; //Poti an GPIO 39 int LED04 = 25; //LED an GPIO 25 int sensor_reading04 = 0; int dutyCycle04 =0; float analog_voltage04; unsigned long delayTime04; const int ledChannel04 = 7; // Auswahl LED-Channel 7; ESP32: 0-15 const int resolution04 = 12; // 12 bit Aufloesung 0-255. Aufloesung beim ESP32 ist 1-16Bit const int frequency04 = 20000; // 20.000 Frequenz in Hz //**************************************************** U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); void setup() { pinMode (LED01, OUTPUT); pinMode (LED02, OUTPUT); pinMode (LED03, OUTPUT); pinMode (LED04, OUTPUT); Serial.begin(115200); u8g2.begin(); //******** Kanal 1 ************************************ ledcSetup(ledChannel01, frequency01, resolution01); // Konfiguration ledcAttachPin(LED01, ledChannel01); // GPIO 27, Auswahl //******** Kanal 2 ************************************ ledcSetup(ledChannel02, frequency02, resolution02); // Konfiguration ledcAttachPin(LED02, ledChannel02); // GPIO 16, Auswahl //******** Kanal 3 ************************************ ledcSetup(ledChannel03, frequency03, resolution03); // Konfiguration ledcAttachPin(LED03, ledChannel03); // GPIO 17, Auswahl //******** Kanal 4 ************************************ ledcSetup(ledChannel04, frequency04, resolution04); // Konfiguration ledcAttachPin(LED04, ledChannel04); // GPIO 17, Auswahl } void loop() { //******** Kanal 1 ************************************ sensor_reading01 = analogRead(ADC_pin01); dutyCycle01 = map(sensor_reading01, 0, 4095, 0, 255); // dutyCycle = map(potiWert, 0, 4095, 0, 255); //******** Kanal 2 ************************************ sensor_reading02 = analogRead(ADC_pin02); dutyCycle02 = map(sensor_reading02, 0, 4095, 0, 511); // dutyCycle = map(potiWert, 0, 4095, 0, 255); //******** Kanal 3 ************************************ sensor_reading03 = analogRead(ADC_pin03); dutyCycle03 = map(sensor_reading03, 0, 4095, 0, 1023); // dutyCycle = map(potiWert, 0, 4095, 0, 255); //******** Kanal 4 ************************************ sensor_reading04 = analogRead(ADC_pin04); dutyCycle04 = map(sensor_reading04, 0, 4095, 0, 4095); // dutyCycle = map(potiWert, 0, 4095, 0, 255); //Kein Mapping Serial.print("Tastverhältnis 1: "); Serial.println(dutyCycle01); // Anzeige des Tastverhältnises im Seriellen Montitor Serial.print("Tastverhältnis 2: "); Serial.println(dutyCycle02); // Anzeige des Tastverhältnises im Seriellen Montitor Serial.print("Tastverhältnis 3: "); Serial.println(dutyCycle03); // Anzeige des Tastverhältnises im Seriellen Montitor Serial.print("Tastverhältnis 4: "); Serial.println(dutyCycle04); // Anzeige des Tastverhältnises im Seriellen Montitor //******** Kanal 1 ************************************ ledcWrite(ledChannel01, dutyCycle01); // Änderung der LED-Helligkeit durch PWM //******** Kanal 2 ************************************ ledcWrite(ledChannel02, dutyCycle02); // Änderung der LED-Helligkeit durch PWM //******** Kanal 3 ************************************ ledcWrite(ledChannel03, dutyCycle03); // Änderung der LED-Helligkeit durch PWM //******** Kanal 4 ************************************ ledcWrite(ledChannel04, dutyCycle04); // Änderung der LED-Helligkeit durch PWM //******** Kanal 1 ************************************ Serial.print("Frequenz:"); Serial.println(frequency01); analog_voltage01 = sensor_reading01 * 3.3 / 4095; Serial.print("Spannung: "); Serial.println(analog_voltage01); Serial.println(); //******** Kanal 1 ************************************ u8g2.setFont(u8g2_font_courR08_tf); u8g2.firstPage(); do { u8g2.setCursor(5, 8); u8g2.print("Frequenz:"); u8g2.setCursor(5, 18); u8g2.print(frequency01); u8g2.print("Hz"); u8g2.setCursor(5, 28); u8g2.print("Spannung:"); u8g2.setCursor(5, 38); u8g2.print(analog_voltage01); u8g2.print(" V"); u8g2.setCursor(5, 48); u8g2.print("Tastverhaeltnis:"); u8g2.setCursor(5, 58); u8g2.print(dutyCycle01); u8g2.print("/255"); } while ( u8g2.nextPage() ); delay(delayTime01); }